package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.Record;
	import engine.tip.tipItem.BookKungfuItem;

	public class FBTaskLogic
	{
		private var _model:ModelLocator
		private static var _self:FBTaskLogic
		//任务类型
		public static var PK_FB:String	=	"PK_FB";
		//采集类型
		public static var COLL_FB:String	=	"COLL_FB";
		public function FBTaskLogic()
		{
			init();
		}
		public static function getInstance():FBTaskLogic
		{
			if(_self == null)
			{
				_self	=	new FBTaskLogic();
			}
			return _self;
		}
		/**
		 * 是否通过当前章节
		 * @param val
		 * @return 
		 * 
		 */		
		public function isCompleteFB(val:int,taskID:int):Boolean
		{
			var isOK:Boolean	=	false;
			var list:Array		=	completeFB;
			if (val == 0&&isCompleteFBTask(taskID)) 
			{
				return true;
			}
			for (var i:int = 0; i < list.length; i++) 
			{
//				&&isCompleteFBTask()
				if (list[i][0] == val&&isCompleteFBTask(taskID))
				{
					isOK	=	true;
				}
			}
			return isOK;
		}
		/**
		 * 是否可以进去副本 
		 * @param val
		 * 
		 */		
		public function isCanIntoFB(val:int):Boolean
		{
			var isOK:Boolean	=	true;
			var list:Array		=	completeFB;
			if (val == 0) 
			{
				return true;
			}
			for (var i:int = 0; i < list.length; i++) 
			{
				if (list[i][0] == val)
				{
					if(list[i][1] == 1)
					{
						isOK	=	false
					}
					else
					{
						isOK	=	true;
					}
				}
			}
			return isOK;
		}
		
		/**
		 * 当前副本是否可以进去扫荡 
		 * @param val
		 * 
		 */		
		public function curFBisCanAnew(fbID:int):Boolean
		{
			var _isOK:Boolean	=	false;
			if (fbID == 0) 
			{
				return true;
			}
			for(var i:int = 0;i<completeFB.length ;i++)
			{
				if(completeFB[i][0] == fbID)
				{
					return  true;
				}
			}

			return _isOK;
		}
		
		/**
		 *  判断是否可以扫荡
		 * @param taskID
		 * @return 
		 * 
		 */
		public function isAnewBtn():Boolean
		{
			var list:Array		=	completeFB;
			for (var i:int = 0; i < list.length; i++) 
			{
				if(list[i][1] == 1)
				{
					return false ; 
				}
			}
			return true ;
		}
		/**
		 * 是否完成了任务 
		 * @param taskID
		 * @return 
		 * 
		 */		
		public function isCompleteFBTask(taskID:int):Boolean
		{
			var isOK:Boolean	=	false;
			var itemArray:Array	=	[];
			var list:Array		=	completeTaskFB;
			var arrayLong:int	=	list.length;
			if(taskID == 0)
			{
				return true;
			}
			for(var i:int = 0; i < arrayLong; i++)
			{
				itemArray	=	completeTaskFB[i];
				if(itemArray[0] == taskID)
				{
					isOK	=	true;
				}
			}
			return isOK;
		}
		private function init():void
		{
			_model	=	ModelLocator.getInstance();
		}
		/**
		 * 获取副本完成表
		 */
		private function get completeFB():Array
		{
			if(_model.scene.CheckProperties("CompletedFB"))
			{
				return (_model.scene.GetPropertiesEx("CompletedFB") as Record).recArr;
			}
			else
			{
				return [];
			}
		}
		/**
		 * 获取副本评分表
		 */
		private function get greadFB():Array
		{
			if(_model.scene.CheckProperties("FBGrade"))
			{
				return (_model.scene.GetPropertiesEx("FBGrade") as Record).recArr;
			}
			else
			{
				return []
			}
		}
		/**
		 * 获取任务完成表 
		 * @return 
		 * 
		 */		
		private function  get completeTaskFB():Array
		{
			if(_model.scene.CheckProperties("Task_Completed"))
			{
				return (_model.scene.GetPropertiesEx("Task_Completed") as Record).recArr;
			}
			else
			{
				return [];
			}
		}
	}
}